`
https://leetcode.cn/problems/house-robber-iv/
`

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var minCapability = function (nums, k) {
  // 只偷不超过 mx 价值的房屋，能否偷到至少 k 个房屋
  const check = (mx) => {
    let f0 = 0, f1 = 0
    for (const x of nums) {
      if (x > mx) {
        f0 = f1
      } else {
        [f0, f1] = [f1, Math.max(f1, f0 + 1)]
      }
    }
    return f1 >= k
  }

  let left = 0, right = Math.max(...nums)
  while (left + 1 < right) {
    const mid = left + Math.floor((right - left) / 2)
    if (check(mid)) {
      right = mid
    } else {
      left = mid
    }
  }
  return right
};